home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / readv < prev    next >
Text File  |  1996-11-09  |  1KB  |  44 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/readv,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: readv,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: readv,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* unix.c.readv: Written by Nick Burrett, 6 October 1996.  */
  18.  
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <string.h>
  22. #include <sys/uio.h>
  23.  
  24. /* Read data from file descriptor FD, and put the result in the
  25.    buffers described by VECTOR, which is a vector of COUNT `struct iovec's.
  26.    The buffers are filled in the order specified.  */
  27. int readv (int fd, const struct iovec *vector, size_t count)
  28. {
  29.   int bytes;
  30.   int bytes_read, i;
  31.  
  32.   /* Find the total number of bytes to be read.  */
  33.   bytes = 0;
  34.   for (i = 0; i < count; ++i)
  35.     {
  36.       bytes_read = read (fd, vector[i].iov_base, vector[i].iov_len);
  37.       if (bytes_read <= 0)
  38.         return -1;
  39.       bytes += bytes_read;
  40.     }
  41.  
  42.   return bytes;
  43. }
  44.